#ifndef TOPOLOGY_H
#define TOPOLOGY_H

#include <map>
#include <vector>

#include "QWord.h"

class Topology
{
public:

	Topology();
	~Topology();
	
	void beginTriangles(int triangleCount);
	void triangle(int triangleIndex, int firstVertexIndex, int secondVertexIndex, int thirdVertexIndex);
	void endTriangles();
	void removeTriangles();
	
	void enterRings();
	int  getPolygonCountInRing();
	int  getPolygonIndexInRing(int offset);
	void leaveRings();


	void beginHalfEdges(int triangleCount);
	void halfEdge(int triangleIndex, int firstVertexIndex, int secondVertexIndex, int thirdVertexIndex);
	void endHalfEdges();
	void removeHalfEdges();

	void enterConnection(int a, int b);
	bool atBoundary();
	int  getFirstPolygonIndexSharedHalfEdge();
	int  getSecondPolygonIndexSharedHalfEdge();
	void leaveConnection();
	
private:

	bool                                                                                mDuringTriangleConstruction;

	std::vector<QWord>                                                                  mVertexIndicesPolygonIndices;
	std::vector<QWord>::iterator                                                        mCurrentIteratorForRing;
	std::vector<QWord>::iterator::difference_type                                       mCurrentCountForRing;
	int                                                                                 mCurrentVertexIndex;
	
	bool                                                                                mDuringHalfEdgeConstruction;
	std::map<QWord, int, lessEightBytes>                                                mHalfEdges;
	QWord                                                                               mTwoPolygons;
	QWord                                                                               mTargetEdge;
};

#endif
